home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
GS_DBASE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-28
|
53KB
|
1,126 lines
{-----------------------------------------------------------------------------
dBase III File Handler
GS_DBASE Copyright (c) Richard F. Griffin
15 November 1990
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This unit handles the objects for all dBase III file (.DBF)
operations.
SHAREWARE -- COMMERCIAL USE RESTRICTED
Changes:
16 Nov 90 - Moved Pack method to GS_dBFld.
02 May 91 - Added an IndexSignature constant to the index units so the
GS_dBase unit can confirm the index unit in use. The flag
IsDB3NDX is true if the dBase III index unit is used. This
is needed to properly convert date fields for an index. The
dBase III index requires a julian date instead of the
character field stored in the record. Most other indexes
use the field as stored (YYYYMMDD).
03 May 91 - Added routine to convert a date field to julian date when
used as an index field in PutRec.
06 Jun 91 - Fixed error in Open that caused the status not to be set
to 'NotUpdated'. Comment close bracket was missing, and
caused the next instruction to be ignorred.
Added a UnInit method to release buffer memory from the
Heap when the file is no longer needed. If the file is
to be used again, it must be reinitialized by calling
the Init method. This allows several files to use the
same object, one after the other.
08 Jan 92 - Changed UnInit to a destructor to make creating and
disposing of dynamic objects possible.
Added GSP_dBase_DB as a pointer of type GS_dBase_DB for
simpler creation of dynamic objects.
02 Feb 92 - Allows multiple indexes to be updated through PutRec.
This will slow the PutRec function as a penalty.
18 Feb 92 - Added File_TOF flag to test for attempt to read beyond
the top of the file. Use like File_EOF test.
27 Feb 92 - Fix made to allow easy change of the master index.
Modified dbfNdxActv from boolean value to GS_Indx_LPtr
index object pointer. This will hold the master index
to be used for GetRec and Find. Will default to the
first file in an Index command. May be set to other
index files by calling the SetIndexMaster procedure
with the order number of the index as the argument.
28 Feb 92 - Added FieldName method to return the name of the field
in the record at the ordered position. For example,
FieldName(2) would return the name of the second field
in the record.
------------------------------------------------------------------------------}
{
┌──────────────────────┐
│ INTERFACE SECTION: │
└──────────────────────┘
}
unit GS_DBASE;
interface
{$D-}
uses
CRT,
DOS,
GS_KeyI,
GS_Date,
GS_FileH, {File handler}
GS_Strng, {String handling Routines}
GS_Error, {Error Handling routines}
GS_DBNdx; {Unit for index operations (.NDX files)}
const
GS_dBase_MaxRecBytes = 4000; {dBASE III record limit }
GS_dBase_MaxRecField = 128; {dBASE III field limit}
GS_dBase_MaxMemoRec = 512; {Size of each block of memo file data}
Next_Record = -1; {Token value passed to read next record}
Prev_Record = -2; {Token value passed to read previous record}
Top_Record = -3; {Token value passed to read first record}
Bttm_Record = -4; {Token value passed to read final record}
GS_dBase_UnDltChr = 32; {Character for Undeleted Record}
GS_dBase_DltChr = 42; {Character for Deleted Record}
type
GS_dBase_Status = (NotOpen, NotUpdated, Updated);
{Flags to indicate status of dBase III file }
GS_dBase_dRec = ^GS_dBase_DataRecord;
{Pointer type used in object descriptions to locate the memory}
{array in bytes for the dBase record. Uses GS_dBase_DataRecord}
{defined below.}
GS_dBase_DataRecord = ARRAY[0..GS_dBase_MaxRecBytes] OF Byte;
{Defines an array of bytes in memory that is as large as the }
{maximum size of a dBase record (GS_dBase_MaxRecBytes).}
{
┌──────────────────────────────────────────────────────────────────┐
│ ******** Data Structure Description ********** │
│ │
│ The following record defines the dBase III file header. Refer │
│ to Appendix A for an explanation of each data element. │
└──────────────────────────────────────────────────────────────────┘
}
GS_dBase_Head = Record
DBType : Byte;
Year : Byte;
Month : Byte;
Day : Byte;
RecCount : LongInt;
Location : Integer;
RecordLen : Integer;
Reserved : Array[1..20] of Byte;
end;
{
┌──────────────────────────────────────────────────────────────────┐
│ ********* Field Descriptor ********* │
│ │
│ This record defines the field descriptor. There is one of │
│ these for each field defined in the database structure. They │
│ are stacked as 32 bytes following the file header record, as │
│ described in Appendix A. │
└──────────────────────────────────────────────────────────────────┘
}
GS_dBase_Field = Record
FieldName : String[10];
{Array[1..11] of Char actually}
{This is to simplify conversion}
FieldType : Char;
FieldAddress : LongInt;
FieldLen : Byte;
FieldDec : Byte;
Reserved : Array[1..14] of Char;
end;
GS_dBase_dFld = ^GS_dBase_DataField;
{Pointer type used in object descriptions to assign memory}
{for storing the field descriptors. }
GS_dBase_DataField = ARRAY[1..GS_dBase_MaxRecField] OF GS_dBase_Field;
{Defines an array of field descriptors (GS_dBase_Field) that}
{is as large as the maximum number of dBase fields allowed}
{(GS_dBase_MaxRecFields).}
GS_dBase_nFld = ^GS_dBase_NameField;
{Pointer type used in object descriptions to assign memory}
{for storing the field name strings. }
GS_dBase_NameField = Array[1..GS_dBase_MaxRecField] OF string[11];
{Defines an array of field name strings (GS_dBase_Field) that}
{is as large as the maximum number of dBase fields allowed}
{(GS_dBase_MaxRecFields).}
{
┌──────────────────────────────────────────────────────────────┐
│ *********** dBase Object Definition ************ │
└──────────────────────────────────────────────────────────────┘
}
GSP_dBase_DB = ^GS_dBase_DB;
GS_dBase_DB = object(GS_KeyI_Objt) {Make it a child for keyboard control}
FileName : string[64]; {Stores FileName of dBase File}
dFile : file; {File Type to reference